<template>
	<view>
		<view >
			<view class="tui-popup-class tui-bottom-popup" :class="{'tui-popup-show':show}" :style="{background:bgcolor,height:height?height+'rpx':'auto'}">
				<view style="height:88vh;overflow-y: auto !important;position: relative;">
					<view style="overflow-y: auto">
						<view class="tab-coupon">
							<view class="left-tab-title">
								<text>优惠券</text>
							</view>
							<view class="close-icon">
								<slot name="close-coupon-popup"></slot>
							</view>
						</view>
						<view class="coupon-card" v-for="(item,index) in couponList" @click="selectCoupon(item,index)" :key="item.id">
							<view>
								<view>
									<text class="new-tag">{{item.tag_name}}</text>
								</view>
								<view class="coupon-content">
									<view class="coupon-item left">
										<view class="title-bold size14">{{item.name}}</view>
										<text class="gray-color size12">{{item.related_type_names}}</text>
									</view>
									<view class="coupon-item right">
										<view class="money"><text class="money-icon">￥</text><text class="money-val">{{item.coupon_money || ''}}</text></view>
										<text class="gray-color size12">{{item.limit_name}}</text>
									</view>
								</view>
								<view class="coupon-date">
									<view class="gray-color date-range size12">{{item.use_start_at}}至{{item.use_expire_at}}</view>
									<view key='type_1' v-show="localCouponId==item.id" class="coupon-state">已选择</view>
								</view>
							</view>
						</view>
						<view v-if="couponList.length==0" style="text-align: center;margin-top:70rpx;">
							<slot name='noData'>暂无数据</slot>
						</view>
						<view class="complete-coupon">
							<slot name="coupon-footer-complete">
							</slot>
						</view>
					</view>
				</view>
			</view>
			<view class="tui-popup-mask" :class="[show?'tui-mask-show':'']" v-if="mask" @tap="handleClose"></view>
		</view>
	</view>
</template>
<script>
	import bottomPopup from "@/components/bottom-popup/bottom-popup"
	export default {
		name: "couponPopup",
		components: {
			bottomPopup
		},
		watch: {
			show(val) {
				let _this = this;
				if (val) {
					_this.active = 0; //每次打开默认满减
					_this.localCouponId = _this.couponId;
					console.log(_this.localOverCouponId)
				}
			}
		},
		// props:['mask', 'couponList','showCouponPopup'],//父组件传过来的数据
		props: {
			couponId: {
				type: String,
				default: ''
			},
			couponList: {
				type: Array,
				default: []
			},
			tabCouponArr: {
				type: Array,
				default: []
			},
			showCouponPopup: {
				type: Boolean,
				default: false
			},
			//是否需要mask
			mask: {
				type: Boolean,
				default: true
			},
			//控制显示
			show: {
				type: Boolean,
				default: false
			},
			//背景颜色
			bgcolor: {
				type: String,
				default: "#fff"
			},
			//高度 rpx
			height: {
				type: Number,
				default: 0
			}
		},
		data() {
			return {
				active: 0,
				currentCoupon: null,
				localCouponId: '',
				checked: false,
			}
		},
		methods: {
			couponTab(i) {
				let _this = this;
				_this.active = i;
				this.currentCoupon = null;
				_this.$emit('getCouponType', this.active)
			},
			selectCoupon(item, index) {
				let _this = this;
				_this.$emit('getOverAndSale', item); //已选择的传到父组件
			},
			handleClose() {
				this.$emit('maskClose', false);
			}
		}
	}
</script>

<style lang="scss">
	// public
	.tui-bottom-popup {
		width: 100%;
		position: fixed;
		left: 0;
		right: 0;
		bottom: 0;
		z-index: 99999;
		visibility: hidden;
		transform: translate3d(0, 100%, 0);
		transform-origin: center;
		transition: all 0.3s ease-in-out;
		min-height: 20rpx;
	}
	.tui-popup-show {
		transform: translate3d(0, 0, 0);
		visibility: visible;
	}
	.tui-popup-mask {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		background: rgba(0, 0, 0, 0.6);
		z-index: 99996;
		transition: all 0.3s ease-in-out;
		opacity: 0;
		visibility: hidden;
	}
	.tui-mask-show {
		opacity: 1;
		visibility: visible;
	}

	// public
	.size14 {
		font-size: 28rpx;
	}
	.size12 {
		font-size: 24rpx;
	}
	.tab-coupon {
		padding-top:28rpx;
		display: flex;
		flex-direction: row;
		height: 50rpx;
		align-items: center;
		font-size: 32rpx;
		font-weight: bold;
		text {
			padding-left: 30rpx;
		}
		// .iconsize{
		// 	font-size:44rpx;
		// }
		.active {
			color: #69A4FE;
		}

		.left-tab-title {
			width: 400rpx;
		}
		.close-icon {
			text-align: right;
			width: 350rpx;
			padding-right: 20rpx;
			font-size: 40rpx;
		}
	}
	.title-bold {
		font-weight: bold;
	}
	.close-icon {
		font-size: 40rpx;
		color: #888888;
	}
	.gray-color {
		color: #888888
	}
	.complete-coupon {
		margin: 30rpx;
		button {
			background: #69A4FE !important;
			border-radius: 50rpx;
		}
	}
	.coupon-card {
		display: flex;
		flex-direction: column;
		border: 1px solid #E5E5E5;
		box-shadow: 0px 0px 5px #E5E5E5;
		margin: 20rpx;
		border-radius: 10rpx;
		height: 260rpx;
		.new-tag {
			background: #FE9B69;
			width: 140rpx;
			padding: 4rpx 20rpx;
			color: white;
			font-size: 20rpx;
			height: 34rpx;
			border-radius: 10rpx 0rpx 10rpx 0rpx;
			position: relative;
			top: -7rpx;
		}
		.coupon-content {
			display: flex;
			flex-direction: row;
			height: 120rpx;
			.coupon-item {
				display: flex;
				flex-direction: column;
				.useRepeat {
					border: 1px solid #FE9B69;
					color: #FE9B69;
					font-size: 20rpx;
					border-radius: 25rpx;
					width: 80rpx;
					text-align: center;
					height: 28rpx;
					line-height: 28rpx;
					padding: 4rpx 14rpx;
					margin-left: 8rpx;
				}
				&.left {
					width: 480rpx;
					padding: 20rpx;
				}
				&.right {
					padding-right: 30rpx;
					width: 240rpx;
					text-align: right;
					.money {
						color: #FF7A36;
						.money-val {
							font-size: 36rpx;
						}
						.money-icon {
							font-size: 24rpx;
						}
					}

				}
			}
		}
		.coupon-date {
			padding-left: 20rpx;
			position: relative;
			border-top: 1px solid #E5E5E5;
			padding-top: 30rpx;
			position: relative;
			&::before {
				content: '';
				width: 10px;
				height: 14px;
				position: absolute;
				border: 1px solid #E5E5E5;
				border-radius: 0 50px 50px 0;
				border-left: none;
				left: -2px;
				top: -10px;
				background: #fff;
			}
			&::after {
				content: '';
				width: 10px;
				height: 14px;
				position: absolute;
				border: 1px solid #E5E5E5;
				border-radius: 50px 0 0 50px;
				// border-left: 1px solid #fff;
				border-right: none;
				right: -2px;
				top: -10px;
				background: #fff;
			}

			.date-range {
				position: relative;
				top: -2rpx;
			}
			.coupon-state {
				position: absolute;
				width: 130rpx;
				height: 44rpx;
				line-height: 44rpx;
				right: 0;
				bottom: -6rpx;
				background: #69A4FE;
				color: white;
				border-radius: 50rpx 0 0 50rpx;
				font-size: 20rpx;
				text-align: center;
			}
		}
	}
</style>
